/**
 * Created by 小敏哥 on 2017/10/10.
 * 订单列表
 */
import React, {Component} from 'react';
import {connect} from 'react-redux';
import style from './index.scss';
import ReTab from '../../components/orderList/orderListTab';
import OrderListItem from '../../components/orderList/orderListItem';
import {getInspectionOrderList} from '../../actions/orderListAction'

class OrderList extends Component {
    constructor(props) {
        super(props);
        this.state = {
            doing: [],
            success: [],
            fail: [],
            all: []
        }
    }

    componentDidMount() {
        let doing = [],
            success = [],
            fail = [],
            all = [];
        this.props.dispatch(getInspectionOrderList({}, (list) => {
            all = list;
            for (let item of list) {
                if(item.orderStatus==2||item.orderStatus==7){
                    doing.push(item);
                }
                else if(item.orderStatus==8||item.orderStatus==9){
                    success.push(item);
                }
                else if(item.orderStatus==4){
                    fail.push(item);
                }
            }
            this.setState({
                doing:doing,
                success:success,
                fail:fail,
                all:all,
            });
        }))
    }

    structList(array){
        return array.length>0? array.map((item,index)=>{
            return <OrderListItem key={item.orderId} createTime={item.createTime} orderAmount={item.orderAmount} status={item.orderStatus} title={item.orderTitle} orderId={item.orderId}/>
        }):<div className={style.emptyContainer}><img className={style.emptyImg} src="./images/orderListEmpty.png"/><div>您暂时还没有订单</div></div>
    }

    render() {
        return <div className={style.container}>
            <ReTab className={style.reTabContainer}>
                <div reTabTitle="处理中">
                    {this.structList(this.state.doing)}
                </div>
                <div reTabTitle="已成功">
                    {this.structList(this.state.success)}</div>
                <div reTabTitle="已撤销">
                    {this.structList(this.state.fail)}</div>
                <div reTabTitle="全部">
                    {this.structList(this.state.all)}</div>
            </ReTab>
        </div>
    }
}


function mapStateToProps(state) {
    return {};
}

export default connect(mapStateToProps)(OrderList)
